#ifndef PW_PBL_MEMORY_HPP
#define PW_PBL_MEMORY_HPP

#include "Span.hpp"
#include <cstddef>
#include <cstdint>
#include <type_traits>

namespace pw_pbl
{
	/// 复制位
	/// @param bit_offset 目的位偏移，支持超过8位偏移
	/// @param bits 总位数
	extern bool copy_bits(const uint8_t *src, Span<uint8_t> tgt, size_t bit_offset, size_t bits);

	template <typename T> requires std::is_trivially_copyable_v<T>
	inline bool copy_bits(const T *src, Span<T> tgt, size_t bit_offset, size_t bits)
	{
		return copy_bits((const uint8_t *)src, {(uint8_t *)tgt.data(), sizeof(T) * tgt.size()}, bit_offset, bits);
	}

} // namespace pw_pbl

#endif // PW_PBL_MEMORY_HPP
